#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 3e5+10;

ll ans1[N],ans2[N],ans[N];
char s[N];
int f[N],sz[N],rk[N],cnt[N],sa[N],id[N],ork[N<<1],px[N],m,n,ht[N],a[N],mx[N],mn[N];

void getSA(){
	m = 300;
	for(int i = 1;i <= n;i++) ++cnt[rk[i] = s[i]];
	for(int i = 1;i <= m;i++) cnt[i] += cnt[i-1];
	for(int i = n;i >= 1;i--) sa[cnt[rk[i]]--] = i;
	for(int h = 1,p;h <= n;h <<= 1,m = p){
		p = 0;for(int i = n;i > n-h;i--) id[++p] = i;
		for(int i = 1;i <= n;i++) if(sa[i] > h) id[++p] = sa[i] - h;
		for(int i = 1;i <= m;i++) cnt[i] = 0;
		for(int i = 1;i <= n;i++) ++cnt[px[i] = rk[id[i]]];
		for(int i = 1;i <= m;i++) cnt[i] += cnt[i-1];
		for(int i = n;i >= 1;i--) sa[cnt[px[i]]--] = id[i];
		for(int i = 1;i <= n;i++) ork[i] = rk[i];
		p = 0;
		for(int i = 1;i <= n;i++)
			rk[sa[i]] = (ork[sa[i-1]+h] == ork[sa[i]+h] && ork[sa[i-1]] == ork[sa[i]]) ? p : ++p;
	}
	for(int i = 1,p = 0;i <= n;i++){
		if(p) p--;
		while(s[i+p] == s[sa[rk[i]-1]+p]) p++;
		ht[rk[i]] = p;
	}
}

int gf(int x){return f[x] == x ? x : f[x] = gf(f[x]);}

void Merge(int x,int y,int l){
	x = gf(x),y = gf(y); f[y] = x;
	ans1[l] += 1ll * sz[x] * sz[y]; sz[x] += sz[y];
	ans[x] = max(ans[x],ans[y]); ans[x] = max(ans[x],max(1ll * mx[x] * mx[y],1ll * mn[x] * mn[y]));
	ans2[l] = max(ans2[l],ans[x]);
	mx[x] = max(mx[x],mx[y]); mn[x] = min(mn[x],mn[y]);
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in; scanf("%s",s+1);
	for(int i = 1;i <= n;i++) a[i] = in;
	getSA(); ans2[n+1] = -1e18;
	for(int i = 1;i <= n;i++) mn[i] = mx[i] = a[i],sz[i] = 1,f[i] = i,id[i] = i,ans2[i] = -1e18,ans[i] = -1e18,ans1[i] = 0;
	sort(id+2,id+n+1,[&](int x,int y){return ht[x] > ht[y];});
	for(int i = 2;i <= n;i++) Merge(sa[id[i]-1],sa[id[i]],ht[id[i]]);
	for(int i = n;~i;i--) ans1[i] += ans1[i+1];
	for(int i = n;~i;i--) ans2[i] = max(ans2[i],ans2[i+1]);
	for(int i = 0;i < n;i++) printf("%lld %lld\n",ans1[i],ans1[i] ? ans2[i] : 0);
	return 0;
}
